import { NodeSize } from '../config'

export default function constant(flow) {
  flow.register('constant', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M699.221333 406.503619c21.162667 0 39.69219-8.996571 55.393524-26.404571 8.192-9.094095 15.823238-21.23581 22.966857-36.303238l1.901715-3.974096-12.897524-7.826285-2.608762 3.803428c-7.046095 10.361905-13.141333 17.578667-18.334476 21.967238a46.933333 46.933333 0 0 1-31.085715 11.434667c-16.554667 0-29.500952-6.631619-39.326476-20.163048a79.067429 79.067429 0 0 1-14.969905-47.274666c0-19.602286 4.608-34.718476 13.385143-45.836191 8.923429-11.312762 19.504762-16.65219 31.890286-16.65219 6.046476 0 10.337524 1.145905 13.385143 3.072 2.633143 1.80419 4.85181 5.144381 6.290286 10.995809l2.243047 8.899048c1.633524 6.290286 4.388571 11.580952 8.484572 15.36a21.820952 21.820952 0 0 0 14.750476 5.680762c6.851048 0 12.848762-2.048 16.896-6.972953a23.161905 23.161905 0 0 0 5.339428-14.555428c0-11.678476-6.948571-21.674667-18.846476-30.037334-12.04419-8.679619-26.307048-12.921905-42.617905-12.921904-26.038857 0-47.811048 9.776762-64.902095 29.208381-16.944762 19.309714-25.429333 42.422857-25.429333 69.095619 0 26.965333 7.704381 48.90819 23.576381 65.194666 15.555048 15.993905 33.792 24.210286 54.515809 24.210286zM784.920381 667.452952l-72.216381 72.192v-233.715809h-29.257143v235.081143l-72.118857-73.45981-20.894476 20.48 106.642286 108.641524 108.544-108.544z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M284.038095 239.494095h199.436191v110.348191h-199.436191z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M242.590476 796.598857h282.331429V198.070857H242.590476v598.528z m41.447619-286.378667h199.436191V629.028571h-199.436191v-118.808381z m0-19.529142V369.371429h199.436191v121.319619h-199.436191z m199.436191-140.824381h-199.436191V239.494095h199.436191v110.372572z m-199.436191 405.308952v-106.617905h199.436191v106.617905h-199.436191z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '增加常量'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
